<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCouponsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('coupons', function (Blueprint $table) {
            $table->increments('id');

            // 商户
            $table->string('shop_id', 20)->default('')->comment('商户ID');

            // 通用属性
            $table->string('name')->default('优惠券/折扣劵')->comment('优惠券/折扣劵名称');
            $table->integer('total_count')->default(0)->comment('总数');
            $table->enum('type', ['amount', 'percent'])->default('amount')->comment('类型：优惠券amount|折扣劵percent');
            $table->integer('type_info')->default(0)->comment('优惠券金额|折扣劵百分百');
            $table->string('describe')->default('')->comment('描述');
            $table->integer('create_time')->default(0)->comment('创建时间');
            $table->integer('update_time')->default(0)->comment('更新时间');

            // 门槛
            $table->integer('limit_amount')->default(0)->comment('使用门槛：满多少可以使用');
            $table->integer('limit_commodity')->default(0)->comment('使用门槛：指定商品ID');
            $table->integer('limit_level')->default(0)->comment('领取门槛：会员等级(身份ID)');
            $table->integer('limit_count')->default(0)->comment('领取门槛：最多领取');
            $table->integer('limit_distribution')->default(0)->comment('领取门槛：分销推广(分销推广ID)');
            $table->integer('effect_time')->default(0)->comment('生效时间');
            $table->integer('expiry_time')->default(0)->comment('到期时间');

            // 索引
            $table->index('shop_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('coupons');
    }
}
